package com.xzc.datastruc.ujava.c07._1_introduction;

public class SN {
    /**
     * @desc Evaluate the sum of the first n integers
     * @problem 1- if n<=0
     * 2- if n is large
     * 3- bookkeeping is cost some computer time
     */
    public static long SumSN(int n) {
        if (n == 1) {
            return 1;
        } else {
            return SumSN(n - 1) + n;
        }
    }

    /**
     * @desc print decimal base 10, recursively
     * @precondition n>=0
     * @problem 1- if n is 10 times decimal
     */
    public static void printDecimal(long n) {
        if (n > 10)
            printDecimal(n / 10);
        System.out.println((char) ('0' + (n % 10)));
    }

    private static final String DIGIT_TABLE = "0123456789abcdef";

    /**
     * @desc print any base 2 between 16
     * @problem 1- if n is base times decimal
     * 2- if base>16
     * 3- if base=0
     * 4- if base=1 it can't progress
     */
    public static void printInt(long n, int base) {
        if (n > base)
            printInt(n / base, base);
        System.out.println(DIGIT_TABLE.charAt((int) n % base));

    }

    public static void main(String[] args) {
//        System.out.println(SumSN(4));
//        System.out.println(SumSN(0));

//        printDecimal(100);
        printInt(99, 8);
    }
}
